#include "test_common.h"

int main(void)
{
	Eix_Server *srv = NULL;
	Eix_Error err1 = { 0 };

	test_common_init();
	srv = test_common_connect();
	if (!srv) return -1;

	while (!test_end)
	{
		test_common_server_process(srv);
		/* send a question */
		if (test_connected)
		{
			Eix_Error err2 = { 0 };
			Test_Message_Question q;
			Test_Message_Answer a;

			q.s = "Who are you?";
			a.s = NULL;
			eix_server_message_send(srv, TEST_MESSAGE_QUESTION, &q, &a, &err1, NULL);
			printf("TC01: recevied '%s' %p\n", a.s, a.s);
			if (a.s) free(a.s);

			/* now force an error async */
			printf("TC01: sending a message that gets an error\n");
			a.s = NULL;
			q.s = "How old are you?";
			eix_server_message_send(srv, TEST_MESSAGE_QUESTION, &q, &a, &err1, NULL);
			if (err1.code != EIX_ERR_NONE)
			{
				printf("TC01: recevied an error as expected\n");
				if (err1.msg)
				{
					printf("TC01: with msg '%s'\n", err1.msg);
					free(err1.msg);
				}
			}
			if (a.s) free(a.s);
			/* now force an error but sync to get it locally */
			test_end = EINA_TRUE;
		}
	}
	if (test_connected)
		eix_server_del(srv);

	return 0;
}
